# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter

import json
class PclPipeline:
    def process_item(self, item, spider):
        return item

    # def __init__(self):
    #     # 初始化时打开一个 JSON 文件，以追加模式写入
    #     self.file = open('output.json', 'a', encoding='utf-8')
    #     # 写入一个左方括号，作为 JSON 数组的起始
    #     self.file.write('[')
    #
    # def process_item(self, item, spider):
    #     # 将 item 转换为 JSON 字符串，并添加换行符
    #     line = json.dumps(dict(item), ensure_ascii=False) + ',\n'
    #     # 将 JSON 字符串写入文件
    #     self.file.write(line)
    #     return item
    #
    # def close_spider(self, spider):
    #     # 指针移到文件倒数第二个字符位置（去掉最后一个多余的逗号）
    #     self.file.seek(self.file.tell() - 2, 0)
    #     # 写入一个右方括号，作为 JSON 数组的结束
    #     self.file.write(']')
    #     # 关闭文件
    #     self.file.close()
